from fastapi import FastAPI
from fastapi.templating import Jinja2Templates


def template_init(app: FastAPI) -> None:
    def render(template_name: str, **data: dict):
        t = Jinja2Templates(directory='templates')
        return t.TemplateResponse(template_name, data)

    @app.on_event("startup")
    def startup() -> None:
        app.state.render = render
